package com.agentfactory.eis.robot;
import com.agentfactory.agentspeak.interpreter.Utilities;
import com.agentfactory.eis.EISControlModule;
import com.agentfactory.logic.update.interpreter.Action;
import com.agentfactory.logic.update.lang.Predicate;

import eis.exceptions.ActException;
import eis.exceptions.NoEnvironmentException;
import eis.iilang.Identifier;
import eis.iilang.Numeral;


/*
 * EIS Module for Robot Ctrl. 
 * Author: Adam
 * 
 */

public class RobotEISModule extends EISControlModule {
	public RobotEISModule() {
		super();

		addAction("installBehaviour(?behaviour)", new Action() {
			@Override
			public boolean execute(Predicate activity) {
				System.out.println("installing behaviour");
				//String entity = Utilities.presenter.toString(activity.termAt(0));
				String behaviour = Utilities.presenter.toString(activity.termAt(0));
				//System.out.println("ENTITY: "+ entity +" BEHAVIOUR: "+ behaviour);
				try {
					System.out.println("AGENT_NAME:"+ agent.getName());
					service.performAction(agent, new eis.iilang.Action("installBehaviour", new Identifier(behaviour)));
				} catch (ActException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return false;
				} catch (NoEnvironmentException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return false;
				}
				return true;
			}
		});


		//left over from the VacWorld Program.

		addAction("light(?state)", new Action() {
			@Override
			public boolean execute(Predicate activity) {
				String state = Utilities.presenter.toString(activity.termAt(0));
				try {
					service.performAction(agent, new eis.iilang.Action("move", new Identifier(state)));
				} catch (ActException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return false;
				} catch (NoEnvironmentException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return false;
				}
				return true;
			}
		});
		addAction("clean", new Action() {
			@Override
			public boolean execute(Predicate activity) {
				try {
					service.performAction(agent, new eis.iilang.Action("clean"));
				} catch (ActException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return false;
				} catch (NoEnvironmentException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return false;
				}
				return true;
			}
		});
	}
}
